package com.inspiration.controller;

import cn.hutool.http.HttpResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Author : Vincent.jiao
 * @Date : 2023/11/4 19:05
 * @Version : 1.0
 */
@Controller
public class UserController {
    String name = "jiao";
    String password = "18011733494";

    @RequestMapping("/login")
    public void login(String name, String pwd,
                      HttpSession session, HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");

        if(this.name.equals(name) && this.password.equals(pwd)) {
            session.setAttribute("user", "true");
            response.getWriter().print("<script>location.href = '/index.html'</script>");
        } else {
            response.getWriter().print("<script>alert('登录错误')</script>");
        }
    }

}
